<?php 
include_once ('./global.php');
$show = $_GET['show'];
$index = $_GET['index'];

if(!$index){
	$index = 0;
}


			//$tmgroupname[0] = $groups[$index] ;
			//$tmgroupname[1] = $groups[$index+1] ;
			
			$ingroups = selGroupName($mt_id);
			$leaderscolor = $colors[$index];
			$players = matchPlayer($mt_id);   
			$start_hole = startHole($mt_id,$rd_id);
			$holeScore   = getHoleScore($mt_id,$rd_id);        //当前洞和当前轮的topar
			$score       = getScore($mt_id);                   //比赛成绩读取
			for ($r=1;$r<=$rd_id;$r++){
				if (!empty($score['to_par'])){
					foreach ($score['to_par'] as $k => $v){
						$topar[$k] += $v[$r];
						
					}
					
				}
			}
			
			 if( 1==1) {   //男子 女子 个人
		
			$gp_id = $ingroups[$index]['id']; 
			
			foreach($ingroups as $i=>$v){
				if($rd_id<2){
					if($i >=4){
						continue;
					}
				}
				$groups[$i] = $v['name'];
				
			}
			
			$summarys = playerSummary($mt_id,$rd_id,$gp_id );
			$sdata = [];
			$rstsummarys = [];
			$index = 0;
			foreach($summarys['rank'] as $n => $v){ 
				$rstsummarys[$index]['rank'] = $v;
				$rstsummarys[$index]['id'] = $n;
				$rstsummarys[$index]['checked'] = $summarys['checked'][$n];
				//$rstsummarys[]['checked'] = $summarys['checked'][$n];
				$sdata['start_hole']['gp_start_hole'][$n] =  $summarys['gp_start_hole'][$n];
				$sdata['start_hole']['gp_start_time'][$n] =  $summarys['gp_start_time'][$n];
				$index++;
			}
			$sdata['playerrank'] = $rstsummarys;
			//$sdata['start_hole'] = $start_hole;
			$sdata['holeScore'] = $holeScore;
			$sdata['players'] = $players;
			$sdata['topar'] = $topar;
			$sdata['score'] = $score;
			$sdata['pars'] = $pars;
			$sdata['cls_id'] = $gp_id;
			//$sdata['isteam'] = 0;
			$sdata['title'] = $groups;
			$sdata['ingroups'] = $ingroups;
			
			 }
			 else{
				 
				 
				 $gp_id = $teamgroups[$index/2-1]['id'];
			
			$teamsummary = teamSummary($mt_id,$rd_id, $gp_id);
	
	
			$teamscoretotal = getTeamTotal($mt_id);
	
			//获取团队成员
			$teamplayers = getTeamPlayer($mt_id,$rd_id);
			//var_dump($teamplayers );
			//获取团队内的个人成绩
			$teamScores = getTeamholescore($teamplayers,$holeScore,$players,$rd_id);
			
			//$sdata = [];
			$rstteamsummarys = [];
			$index = 0;
			foreach($teamsummary as $n => $v){
				$rstteamsummarys[$index]['rank'] = $v['rank'];
				$rstteamsummarys[$index]['tm_name'] = $v['tm_name'];
				$rstteamsummarys[$index]['id'] = $n;
				//$rstsummarys[]['checked'] = $summarys['checked'][$n];
				//$rstsummarys[]['checked'] = $summarys['checked'][$n];
				$index++;
			}
			//$sdata['playerrank'] = $rstsummarys;
			$sdata['teamrank'] = $rstteamsummarys;
			
			$sdata['teamscoretotal'] = $teamscoretotal;
			$sdata['teamplayers'] = $teamplayers;
			$sdata['teamScores'] = $teamScores;
			$sdata['pars'] = $pars;
			$sdata['title'] = $groups;
			 }
			
			echo json_encode($sdata);exit;

	?>


			
			
			


		



	
	